<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>
<c:set var="url" value="<%=basePath%>"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<script src="${url }/js/jquery-1.11.0.js"></script>
<title>Ajax Test</title>

</head>
<body>
请输入123或者其他数字测试<br>
	<input type="text" name="name" id="name"/>
	<input type="submit" value="登录" onclick="ajaxTest();"/>
	
	<div id="result"></div>
<script type="text/javascript">
	function ajaxTest(){
		var inputData="name="+$("#name").val() ;
		$.ajax({
		data:inputData,
		type:"GET",
		dataType: 'json',
		url:"/ajax/testlogin",
		error:function(data){
			$("#result").html(data.msg) ;
		},
		success:function(data){
			/**
			alert("success:"+data.msg);
			**/
			$("#result").html(data.msg) ;
		}
		});
	}
</script>

	
	 <button onclick="$.clickJson()">点我</button>
        <div id="div1"></div>
        
        <script type="text/javascript">
        	$.extend({clickJson:function(){
        		  var student={"id":"3","name":"顾军先","sex":"男"};
        		  $.ajax({
					   type: "POST",
					   url:"/ajax/each",
					   contentType:"application/json;charset=utf-8",
					   //contentType:"application/json",
					   dataType: "json",
					   data:JSON.stringify(student),
					   success: function(msg){
						   $("#div1").html("");
					   	   //msg : 返回的json对象     // i :元素下标   , s: 遍历出来的学生对象
					       $.each(msg,function(i,s){
					       		$("#div1").append("<p>"+s.id+","+s.name+","+s.sex+"</p>");
					       });
					   }
				});
        	}});
        </script>
</body>
</html>
